﻿using FarmSmartSleep.Common.Domain.BeginTable;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.SelectFile
{
    /// <summary>
    ///  earMasListListHandler
    /// </summary>
    public class EarMasListListHandler : IRequestHandler<EarMasListCommon, ResultT<SleepInfor>>
    {
        private readonly IBaseRepository<SleepInfor> sleepInfobaseRepository;
        /// <summary>
        ///  earMasListListHandler
        /// </summary>
        /// <param name="sleepInfobaseRepository"></param>
        public EarMasListListHandler(IBaseRepository<SleepInfor> sleepInfobaseRepository)
        {
            this.sleepInfobaseRepository = sleepInfobaseRepository;
        }
        /// <summary>
        /// 档案
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ResultT<SleepInfor>> Handle(EarMasListCommon request, CancellationToken cancellationToken)
        {
            var result = new ResultT<SleepInfor>() { Code = (int)CodeEnum.search };
            var listQuery =  sleepInfobaseRepository.GetAll().Where(c => c.SleepInforId == request.SleepInforId); ;
           
           
            
            // 执行查询并转为列表
            var list = await listQuery.FirstOrDefaultAsync(cancellationToken);
            if (list==null)
            {
                result.Messege = "暂无数据";
                return result;
            }
            
            result.Code=(int)CodeEnum.success;
            result.Item = list;
            return result;
        }
    }
}
